﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace CSSAdriverapp
{
    /// <summary>
    /// Interaction logic for AddVehicleType.xaml
    /// </summary>
    public partial class AddVehicleType : Window
    {
        public AddVehicleType()
        {
            InitializeComponent();
            }

        private void addTypeButton_Click(object sender, RoutedEventArgs e)
        {
            if (vehicleTypeTextbox.Text != "")
            {
                nameFieldMissingLabel.Visibility = System.Windows.Visibility.Hidden;
                DataClassesDataContext db = new DataClassesDataContext();
                // Create a new Order object.
                var vtype = new VehicleType
               {
                   Name = vehicleTypeTextbox.Text,
                   NumOfSeats = ((int)seatSlider.Value)

               };

                // Add the new object to the Orders collection.
                db.VehicleTypes.InsertOnSubmit(vtype);

                // Submit the change to the database.
                try
                {
                    db.SubmitChanges();
                    typeAddedSuccessfullyLabel.Visibility = System.Windows.Visibility.Visible;
                }
                catch (Exception c)
                {
                    Console.WriteLine(c);
                    // Make some adjustments.
                    // ...
                    // Try again.
                    db.SubmitChanges();
                }
            }
            else
            {
                nameFieldMissingLabel.Visibility = System.Windows.Visibility.Visible;
            }
        }


    }
}
